<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String contextPath = request.getContextPath();%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="http://g.alicdn.com/bui/bui/1.1.17/css/bs3/dpl.css" rel="stylesheet">
<link href="http://g.alicdn.com/bui/bui/1.1.17/css/bs3/bui.css" rel="stylesheet">
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/assets/css/font-awesome.min.css" />
<script src="${pageContext.request.contextPath}/resources/jslib/jquery-2.1.3.min.js"></script>
<script src="http://g.alicdn.com/bui/seajs/2.3.0/sea.js"></script>
<script src="http://g.alicdn.com/bui/bui/1.1.17/config.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/js/system.js"></script>
<script type="text/javascript">
	BUI.use(['bui/extensions/treegrid','bui/data','bui/grid'],function(TreeGrid,Data,Grid){
		var editing=new Grid.Plugins.DialogEditing({
   		   contentId : 'userModal', //设置隐藏的Dialog内容
           triggerCls : 'btn-edit', //触发显示Dialog的样式
           editor : {
          	 success:function(){
          		 var editor=this,
          		 form=editor.get('form'),
          		 editType = userEditing.get('editType'),//add 或者 edit
          		 url='<%=contextPath%>/user/saveOrUpdate.action';
          		 form.valid();
          		 if(form.isValid())
          		 {
                       form.ajaxSubmit({ //表单异步提交
                         url : url,
                         success : function(data){
                           if(data.success)
                           {
                          	 editor.accept();
                           }
                           else
                           {
                          	 BUI.Message.alert("保存用户失败",'error');
                           }
                         },
                         error:function(){
    	            		 BUI.Message.alert("保存用户失败",'error');
    	            	   }
                       });
                   }
          	 }
          	
           }
   	});	
		var treeStore=new Data.TreeStore({
			  url:'<%=contextPath%>/privilege/privileges.action',
	    	  autoLoad : true,
	    	  pidField : 'pid',
		});
		
		var treeGrid=new TreeGrid({
			render:"#tb_privilege",
			store:treeStore,
			forceFit : true,
			plugins :[editing]
			columns:[
			   {title:'资源名称',width : 200,dataIndex:'name'},
			   {title:'权限路径',width : 250,dataIndex:'url'},
			   {title:'权限类型',width : 70,elCls:'center',dataIndex:'privilegeType',renderer:function(value){
				   if(value==="MENU")
						return "菜单";
					else if(value==="FUNCTION")
						return "功能";
					else if(value==="BUTTON")
						return "按钮";
					else if(value==="URL")
						return "链接";
			   }},
			   {title:'是否启用',elCls:'center',width : 70,dataIndex:'privilegeEnabled',renderer:function(value){
				   if(value)
						return '<input type="checkbox" disabled="disabled" checked/>';
					else
						return '<input type="checkbox" disabled="disabled"/>';
			   }},
			   {title:'权限描述',width : 200,dataIndex:'description',renderer:function(value){
				   if(value){
					   var title=value;
					   if(title.length>15)
						   title=title.substr(0,15)+"...";
						return system.formatString('<span title="{0}">{1}</span>',value,title);
					}
			   }},
			   {title:'操作',width : 100,dataIndex:'name',renderer:function(value, row){
						var str='';
						if(row.url&&row.privilegeType=="MENU")
							str+=system.formatString('&nbsp;&nbsp;<i class="icon-plus" onClick="addFun(\'{0}\')" title="添加子权限" style="cursor:pointer;"/>',row.id);
						else if(row.privilegeType=="FUNCTION")
						{
							str+=system.formatString('&nbsp;&nbsp;<i class="icon-edit" onClick="editFun(\'{0}\')" title="编辑权限" style="cursor:pointer;"/>',row.id);
							str+=system.formatString('&nbsp;&nbsp;&nbsp;<i class="icon-remove" onClick="delFun(\'{0}\')" title="删除权限" style="cursor:pointer;"/>&nbsp;&nbsp;',row.id);
						}
						return str;
			   }}
			]
			 
		});
		treeGrid.render();
		
		
  	
	});
</script>
</head>
<body>
	<table id="tb_privilege" data-options="fit:true,border:false" ></table>
	<div id="privilegeModal" style="display: none;"> 
		<form class="form-horizontal" id="userForm" method="post">
			<input name="id" type="hidden" >
		</form>
	</div>
</body>
</html>